package org.linlinjava.litemall.db.service;

 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.linlinjava.litemall.db.dao.LitemallShopLogMapper;
import org.linlinjava.litemall.db.domain.LitemallShopLog;
import org.linlinjava.litemall.db.domain.LitemallShopLogExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallShopLogService {
    @Resource
    private LitemallShopLogMapper litemallShopLogMapper;

    public IPage<LitemallShopLog> querySelective(Integer shopId, String content, Integer page,
                                                 Integer limit, String sort, String order) {
        LambdaQueryWrapper<LitemallShopLog> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(null != shopId,LitemallShopLog::getShopId,shopId);
        lambdaQueryWrapper.like(!StringUtils.isEmpty(content),LitemallShopLog::getContent,content);
        lambdaQueryWrapper.eq(LitemallShopLog::getDeleted,false);
        return litemallShopLogMapper.selectPage(new Page<>(page,limit),lambdaQueryWrapper);
    }

    public int updateById(LitemallShopLog shop) {
        return litemallShopLogMapper.updateByPrimaryKeySelective(shop);
    }

    public void deleteById(Integer id) {
        litemallShopLogMapper.logicalDeleteByPrimaryKey(id);
    }

    public void add(LitemallShopLog shop) {
        shop.setAddTime(LocalDateTime.now());
        litemallShopLogMapper.insertSelective(shop);
    }

    public LitemallShopLog findById(Integer id) {
        return litemallShopLogMapper.selectByPrimaryKeySelective(id);
    }

    public List<LitemallShopLog> all() {
        LitemallShopLogExample example = new LitemallShopLogExample();
        example.or().andDeletedEqualTo(false);
        return litemallShopLogMapper.selectByExample(example);
    }
}
